package com.example.clock;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.IBinder;

import com.iflytek.cloud.InitListener;
import com.iflytek.cloud.SpeechError;
import com.iflytek.cloud.SpeechSynthesizer;
import com.iflytek.cloud.SpeechUtility;
import com.iflytek.cloud.SynthesizerListener;
import com.iflytek.sunflower.FlowerCollector;

public class PlayMusic extends Service {
	private MediaPlayer myMediaPlayer;
	private SpeechSynthesizer mTts;
	/**
	 * 初始化监听。
	 */
	private InitListener mTtsInitListener = new InitListener() {
		@Override
		public void onInit(int code) {

		}
	};
	/**
	 * 合成回调监听。
	 */
	private SynthesizerListener mTtsListener = new SynthesizerListener() {

		@Override
		public void onSpeakBegin() {
		}
		@Override
		public void onSpeakPaused() {
		}
		@Override
		public void onSpeakResumed() {
		}
		@Override
		public void onBufferProgress(int percent, int beginPos, int endPos,
									 String info) {
		}
		@Override
		public void onSpeakProgress(int percent, int beginPos, int endPos) {
			// 播放进度
		}
		@Override
		public void onCompleted(SpeechError error) {
		}
		@Override
		public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
			// 以下代码用于获取与云端的会话id，当业务出错时将会话id提供给技术支持人员，可用于查询会话日志，定位出错原因
			// 若使用本地能力，会话id为null
			//	if (SpeechEvent.EVENT_SESSION_ID == eventType) {
			//		String sid = obj.getString(SpeechEvent.KEY_EVENT_SESSION_ID);
			//		Log.d(TAG, "session id =" + sid);
			//	}
		}
	};
	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		//myMediaPlayer = MediaPlayer.create(this, R.raw.tx);

			mTts = SpeechSynthesizer.createSynthesizer(PlayMusic.this, mTtsInitListener);
			// 设置参数
			mTts.startSpeaking(MainActivity.myAlert, mTtsListener);
			//myMediaPlayer = MediaPlayer.create(this, R.raw.tx);

			super.onCreate();

	}

	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		//myMediaPlayer.stop();
		super.onDestroy();
	}

	@Override
	public void onStart(Intent intent, int startId) {
		// TODO Auto-generated method stub
		//myMediaPlayer.start();
		super.onStart(intent, startId);
	}



}
